package com.amt.iptvsetting;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import androidx.multidex.MultiDex;

import android.os.StrictMode;
import android.util.Log;

import com.alibaba.android.arouter.launcher.ARouter;
import com.amt.iptvsetting.business.virtual.VirtualAPKManager;
import com.amt.iptvsetting.dagger.DaggerAppComponent;
import com.app.annotationlib.ZBindView;
import com.app.common.CommonManagerKt;
import com.app.datamanagermodule.DataManagerModuleKt;
import com.app.notificationmodule.NotificationModuleKt;
import com.app.reactnativelearnmodule.ReactNativeManager;
import com.app.reactnativelearnmodule.ReactNativeModuleLearnManagerKt;
import com.app.weexlearnmodule.ZWeexLearnModule;

import javax.inject.Inject;

import butterknife.ButterKnife;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import dagger.android.support.DaggerApplication;
import io.flutter.view.FlutterMain;



public class ZApplication extends Application implements HasActivityInjector {

    private static final String TAG = ZApplication.class.getSimpleName();

    @Inject
    DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;

    @ZBindView(10)
    private String hello;

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        VirtualAPKManager.init(base);
    }

    @Override
    public void onCreate() {
        super.onCreate();


        MultiDex.install(this);

        DaggerAppComponent.builder().create(this).inject(this);

        Log.i(TAG, "onCreate: ");
        ButterKnife.setDebug(true);

        ApplicationInfo applicationInfo = getApplicationInfo();

        String sourceDir = applicationInfo.sourceDir;
        Log.i(TAG, "onCreate: sourceDir -> " + sourceDir);

        ARouter.openLog();     // 打印日志
        ARouter.openDebug();   // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)

        ARouter.init(this);

        FlutterMain.startInitialization(this);

        ZWeexLearnModule.init(this);

        CommonManagerKt.setContext(this);

        DataManagerModuleKt.init(this);

        NotificationModuleKt.create(this);

        ReactNativeModuleLearnManagerKt.ReactNativeModule_init(this);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        Log.i(TAG, "onTerminate: ");
    }

    private void enabledStrictMode() {
        StrictMode.setThreadPolicy(
                new StrictMode.ThreadPolicy.Builder()
                        .detectAll()
                        .penaltyLog()
                        .penaltyDeath()
                        .build()
        );
    }

    @Override
    public AndroidInjector<Activity> activityInjector() {
        return dispatchingAndroidInjector;
    }



}
